import http from "@/http";
import { id } from "element-plus/es/locale";

export const userListApi = (params: IUserListParams): RES<IUserListModel> =>
  http.get("/admin/list", { params });

export const switchUserStatusApi = (id: number, status: number): RES<number> =>
  http.post(`/admin/updateStatus/${id}?status=${status}`);

export const addUserApi = (params: IUserModel): RES<IUserModel> =>
  http.post("/admin/register", params);

export const getUserById = (id: number): RES<IUserModel> =>
  http.get(`/admin/${id}`);

export const updateUser = (params: IUserModel): RES<number> =>
  http.post(`/admin/update/${params.id}`, params);

export const getRoleListApi = (): RES<IRoleModel[]> =>
  http.get("/role/listAll");

export const getRolesByUserIdApi = (adminId: number): RES<IRoleModel[]> =>
  http.get(`/admin/role/${adminId}`);

export const updateuserRolesApi = (id: number, ids: number[]) =>
  http.post(`/admin/role/update?adminId=${id}&roleIds=${ids.join(",")}`);

export const RoleListAPI = (
  params: IUserListParams
): RES<ITableResult<IRoleModel>> => http.get(`/role/list`, { params });

export const switchRoleStatusAPI = (id: number, status: number): RES<number> =>
  http.post(`/role/updateStatus/${id}?status=${status}`);

export const editRoleAPI = (params: IRoleModel): RES<number> =>
  http.post(`/role/update/${params.id}`, params);

export const addRoleAPI = (params: IRoleModel): RES<IRoleModel> =>
  http.post("/role/create", params);

export const getRourcelistByRoleIdApi = (
  roleId: number
): RES<IResourceModel[]> => http.get(`/role/listResource/${roleId}`);

export const resourceListAllApi = (): RES<IResourceModel[]> =>
  http.get("/resource/listAll");

export const resourceCategoryAllApi = (): RES<IResourceCategoryModel[]> =>
  http.get(`/resourceCategory/listAll`);

export const allocResourceApi = (params: allocResourceParams): RES<number> =>
  http.post(
    `/role/allocResource?roleId=${
      params.roleId
    }&resourceIds=${params.resourceIds.join(",")}`
  );

export const treeListApi = (): RES<ItreeMenu[]> => http.get("/menu/treeList");
